import { requestClient } from '#/api/request';

// 手牌相关接口
export interface HandCard {
  id: number;
  number: string;
  status: string;
  type: string;
  team?: string;
  room?: string;
  openTime?: string;
  totalConsumption?: string;
  remarks?: string;
  icon?: string;
}

export interface HandCardQuery {
  pageNo?: number;
  pageSize?: number;
  status?: string;
  type?: string;
  number?: string;
}

export interface HandCardStatistics {
  status: string;
  count: number;
  percentage: string;
}

export interface ChildCardRequest {
  cardNumber: string;
  childCount: number;
}

export interface TeamCardRequest {
  cardNumbers: string[];
}

export interface ModifyStatusRequest {
  cardNumber: string;
  newStatus: string;
  remarks?: string;
  operator: string;
}

export interface ReplaceCardRequest {
  oldCardNumber: string;
  newCardNumber: string;
  remarks?: string;
  operator: string;
}

export interface RevokeCardRequest {
  cardNumber: string;
}

export interface QuickOrderRequest {
  cardNumber: string;
  items: Array<{
    name: string;
    price: number;
    quantity: number;
  }>;
}

export interface QuickTransferRequest {
  fromCardNumber: string;
  toCardNumber: string;
  items: Array<{
    name: string;
    price: number;
    quantity: number;
  }>;
}

export interface MergeCardsRequest {
  cardNumbers: string[];
}

// 获取手牌列表
export function getHandCardList(params: HandCardQuery) {
  return requestClient.get<HandCard[]>('/spa/hand-card/list', { params });
}

// 获取手牌统计信息
export function getHandCardStatistics() {
  return requestClient.get<HandCardStatistics[]>('/spa/hand-card/statistics');
}

// 儿童开牌
export function openChildCard(data: ChildCardRequest) {
  return requestClient.post('/spa/hand-card/child-open', data);
}

// 团队开牌
export function openTeamCard(data: TeamCardRequest) {
  return requestClient.post('/spa/hand-card/team-open', data);
}

// 修改手牌状态
export function modifyHandCardStatus(data: ModifyStatusRequest) {
  return requestClient.post('/spa/hand-card/modify-status', data);
}

// 更换手牌
export function replaceHandCard(data: ReplaceCardRequest) {
  return requestClient.post('/spa/hand-card/replace', data);
}

// 撤销手牌
export function revokeHandCard(data: RevokeCardRequest) {
  return requestClient.post('/spa/hand-card/revoke', data);
}

// 快速下单
export function quickOrder(data: QuickOrderRequest) {
  return requestClient.post('/spa/hand-card/quick-order', data);
}

// 快速转账
export function quickTransfer(data: QuickTransferRequest) {
  return requestClient.post('/spa/hand-card/quick-transfer', data);
}

// 合并手牌
export function mergeHandCards(data: MergeCardsRequest) {
  return requestClient.post('/spa/hand-card/merge', data);
}

// 搜索手牌
export function searchHandCard(cardNumber: string) {
  return requestClient.get<HandCard>(`/spa/hand-card/search/${cardNumber}`);
}

// 获取已结账单
export function getSettledBills(params: {
  cardNumber?: string;
  billNumber?: string;
  startDate?: string;
  endDate?: string;
  pageNo?: number;
  pageSize?: number;
}) {
  return requestClient.get('/spa/hand-card/settled-bills', { params });
}

// 获取已开手牌
export function getOpenedCards(params: {
  cardNumber?: string;
  status?: string;
  pageNo?: number;
  pageSize?: number;
}) {
  return requestClient.get('/spa/hand-card/opened-cards', { params });
}

// 获取OTA处理数据
export function getOtaProcessing(params: {
  serialNumber?: string;
  billNumber?: string;
  startDate?: string;
  endDate?: string;
  pageNo?: number;
  pageSize?: number;
}) {
  return requestClient.get('/spa/hand-card/ota-processing', { params });
}

// 获取客流量统计
export function getTrafficStatistics() {
  return requestClient.get<{
    todayTraffic: number;
    yesterdayTraffic: number;
  }>('/spa/hand-card/traffic-statistics');
}
